package com.u2b.servlet;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.u2b.dispatcher.UserDispatcher;
import com.u2b.global.utils.Constants;
import com.u2b.servlet.utils.ParameterParser;
import com.u2b.servlet.utils.SendToClient;
import com.u2b.servlet.utils.UrlInterceptor;

/*
 *          1 ./user/login
 *          2./user/register (服务器备注:需要提供create_time服务)
 *          3./user/uid      (服务器备注:需要提供distance服务)
 *          4./user/zone
 *          5./user/setEmail
 *          6./user/setMultiple
 *          7./user/setPassword
 *          8./user/setVideo
 *          客户端注意了:一定要注意登陆与注册空字符串的问题,在本地就应该检验字符串是否非空
 */

public class UserAction extends HttpServlet
{

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException
    {

        SendToClient sendToClient = new SendToClient();
        String action = UrlInterceptor.intercept(request);
        ParameterParser ppr = new ParameterParser();
        UserDispatcher userDispatcher = new UserDispatcher();
        HashMap<String, Object> initValues = ppr.initFormRequest(request);
        Object obj = userDispatcher.dispatcer(action, initValues, request);
        sendToClient.sendMessage(request, resp, obj);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doPost(req, resp);

    }
}
